import Taro, {Component} from '@tarojs/taro'
import {connect} from '@tarojs/redux'
import {View, Text, Input, Picker} from '@tarojs/components'
import './index.less'
import _pickBy from 'lodash/pickBy'
import _startsWith from 'lodash/startsWith'
import {AtTabBar, AtIcon, AtButton} from 'taro-ui'

@connect(({recruitmentDetails, loading}) => ({
  recruitmentDetails,
  loading
}))

export default class recruitmentDetails extends Component {

  config = {
    navigationBarTitleText: '详细信息'
  }

  constructor(props) {
    super(props)
    this.state = {
      current: 0
    }
  }

  componentWillMount() {
  }

  componentDidMount() {
    const {dispatch, recruitmentDetails} = this.props;
    const {
      listData
    } = recruitmentDetails;
    console.log('qqq', listData)
    dispatch({type: 'recruitmentDetails/getDetails'})
  }

  componentWillUnmount() {
  }

  componentDidShow() {
  }

  componentDidHide() {
  }

  // 分享小程序
  onShareAppMessage(options) {
    const {recruitmentDetails,dispatch} = this.props;
    const {listData} = recruitmentDetails;
    dispatch({type: 'recruitmentDetails/addView'})
    // 设置菜单中的转发按钮触发转发事件时的转发内容
    var shareObj = {
      title: "江苏厂管家",        // 默认是小程序的名称(可以写slogan等)
      path: `pages/recruitmentDetails/index?id=${listData.id}`,        // 默认是当前页面，必须是以‘/’开头的完整路径
    };

    return shareObj;
  }

  //打电话
  phoneCall(num, e) {
    Taro.makePhoneCall({phoneNumber: num})
    //阻止事件向上级冒泡
    e.stopPropagation();
  }

  render() {
    const {
      recruitmentDetails, dispatch
    } = this.props;
    const {
      listData
    } = recruitmentDetails;
    const updateState = (obj) => {
      dispatch({
        type: 'recruitmentDetails/updateState',
        payload: {
          ...obj
        }
      })
    }
    return (
      <View className='recruitmentDetails'>
        <View className='recruitment_type'>
          {listData.type == '0' ? '求职' : '招聘'}
        </View>
        <View className="recruitment_main">
          <View className='at-row at-row--wrap at-row__align--start recruitment_title'>
            <View className='at-col at-col-2 at-col--wrap recruitment_name'> 标题：</View>
            <View className='at-col at-col-9 at-col--wrap'>{listData['title']}</View>
          </View>
          <View className='at-row at-row--wrap at-row__align--start recruitment_description'>
            <View className='at-col at-col-8 at-col--wrap recruitment_content'>{listData['description']}</View>
          </View>
        </View>
        <View className='tabBarBtm'>
          <View className='at-row'>
            <View className='at-col-12'>
            {listData.showCellphone==true? 
              <View className='shareBtn'>
                <AtButton circle onClick={this.phoneCall.bind(this, listData['cellphone'] || '13966110110')}>
                  <AtIcon value='phone' color='#fff' size='18'></AtIcon>
                  <View className='tabBarText'>{listData['contact']},{listData['cellphone']!=null && listData['cellphone']!= ''?listData['cellphone']:'电话暂无'}</View>
                </AtButton>
              </View>: 
               <View className='shareBtn'>
               <AtButton circle openType='share'>
                 <AtIcon value='external-link' color='#fff' size='18'></AtIcon>
                 <View className='tabBarText'>分享至朋友圈&ensp;&ensp;查看电话</View>
               </AtButton>
             </View>}
            </View>

          </View>
        </View>
      </View>
    )
  }
}
